//101. 对称二叉树
//思路：1、将一棵树一分为二，左右子树分别看作是两棵树
//2、再使用判断两棵树是否相同的思路，左子树的左与右子树的右是否相同

#include <stdio.h>
#include <stdbool.h>

struct TreeNode {
	int val;
	struct TreeNode* left;
	struct TreeNode* right;
};
bool isSameTree(struct TreeNode* p, struct TreeNode* q)
{
	if (NULL == p && NULL == q)
		return true;
	else if ((NULL == p && NULL != q)
		|| (NULL != p && NULL == q))
		return false;

	if (p->val != q->val)
		return false;

	return isSameTree(p->left, q->right)
		&& isSameTree(p->right, q->left);
}
bool isSymmetric(struct TreeNode* root) {
	if (NULL == root)
		return false;

	return isSameTree(root->left, root->right);
}